<?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date') ?>
<title><?= $sf_response->getTitle() ?></title>

<?php use_stylesheet('/sf/sf_admin/css/main') ?>

<div id="sf_admin_container">

<!--<h3>DASH BOARD</h3>-->
<div id="sf_admin_content">

<table width="100%" border="0"> <tr><td width="18%"></td>
<td>
<?if (isset($BOMCount) || isset($MR2Count) || isset($MR3Count) || isset($POCount) ) {?>
<h4>APPROVAL</h4>

<table id ='tast' cellspacing="1" class="sf_admin_list" width="100%">
<? if (isset($BOMCount) ) {?>
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" width="50%">BOM</th>
      <th id="sf_admin_list_th_productcode" >Action</th>
</tr>
</thead>
<tr class="sf_admin_row_1">
      <td >
      <? 
          if (isset($BOMCount) && $BOMCount) {
            echo $BOMCount . ' item';
            if ($BOMCount>1)
                echo 's'; 
            echo ' waiting for approval';
          } else {
            echo 'No item';
          } 
      ?>
      </td>
      <td >
      <a href=<?echo url_for('approval/ListApprovalObject?authenticationMain=APPROVE_BOM&authenticationSub=PR_APPROVE_MR&mod=BOM&backURL=')?>>View Approval List</a>
      </td>
</tr>
<?}?>

<? if (isset($MR2Count) ) {?>
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" >MR Sub</th>
      <th id="sf_admin_list_th_productcode" >Action</th>
</tr>
</thead>
<tr class="sf_admin_row_1">
      <td>
      <? 
          if (isset($MR2Count) && $MR2Count) {
            echo $MR2Count . ' item'; 
            if ($MR2Count>1) 
                echo 's'; 
            echo ' waiting for approval';
          } else {
            echo 'No item';
          } 
      ?>
      </td>
      <td>
      <a href=<?echo url_for('approval/ListApprovalObject?authenticationMain=APPROVE_MRSUBSTK&authenticationSub=APPROVE_MRSUBFTR&mod=MRSUB&backURL=')?>>View Approval List</a>
      </td>
</tr>
<?}?>

<? if (isset($MR3Count) ) {?>
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" >MR Raw</th>
      <th id="sf_admin_list_th_productcode" >Action</th>
</tr>
</thead>
<tr class="sf_admin_row_1">
      <td>
      <? 
          if (isset($MR3Count) && $MR3Count) {
            echo $MR3Count . ' item'; 
            if ($MR3Count>1) 
                echo 's'; 
            echo ' waiting for approval';
          } else {
            echo 'No item';
          } 
      ?>
      </td>
      <td>
      <a href=<?echo url_for('approval/ListApprovalObject?authenticationMain=APPROVE_MRRAW&authenticationSub=PR_APPROVE_MRRAW&mod=MRRAW&backURL=')?>>View Approval List</a>
      </td>
</tr>
<?}?>

<? if (isset($POCount) ) {?>
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" >PO</th>
      <th id="sf_admin_list_th_productcode" >Action</th>
</tr>
</thead>
<tr class="sf_admin_row_1">
      <td>
      <? 
          if (isset($POCount) && $POCount) {
            echo $POCount . ' item'; 
            if ($POCount>1) 
                echo 's'; 
            echo ' waiting for approval';
          } else {
            echo 'No item';
          } 
      ?>
      </td>
      <td>
      <a href=<?echo url_for('approval/ListApprovalObject?authenticationMain=APPROVE_PO&authenticationSub=PR_APPROVE_PO&mod=PO&backURL=')?>>View Approval List</a>
      </td>
</tr>
<?}?>
</table>

<?}?>


<?if ( (isset($RvMRList['MR']) && count($RvMRList['MR'])> 0 ) || (isset($RvMRList['MR2']) && count($RvMRList['MR2'])> 0 ) || (isset($RvMRList['MR3']) && count($RvMRList['MR3'])> 0 )) {?>
<h4>REVISE</h4>

<table id ='tast' cellspacing="1" class="sf_admin_list" width="100%">

<thead>
<tr>
      <th id="sf_admin_list_th_productcode" width="50%">MR</th>
      <th id="sf_admin_list_th_productcode" >Action</th>
</tr>
</thead>
<?
$key =0;
if ( (isset($RvMRList['MR']) && count($RvMRList['MR'])> 0 ) ) {
foreach ($RvMRList['MR'] as $mr)  {?>
<tr class="sf_admin_row_<?echo ($key++)%2?>">
      <td >
      <? echo $mr->getMrno().':'.$mr->getProject();
      ?>
      </td>
      <td >
      <a href=<?echo url_for('po/resolveRVMR?mr_id='. $mr->getId())?>>Resolve</a>
      </td>
</tr>
<?} }?>


<?
if ( (isset($RvMRList['MR2']) && count($RvMRList['MR2'])> 0 ) ) {
foreach ($RvMRList['MR2'] as $mr)  {?>
<tr class="sf_admin_row_<?echo ($key++)%2?>">
      <td >
      <? echo $mr->getMrno();
      ?>
      </td>
      <td >
      <a href=<?echo url_for('po/resolveRVMR?mr2_id='. $mr->getId())?>>Resolve</a>
      </td>
</tr>
<?} }?>


<?
if ( (isset($RvMRList['MR3']) && count($RvMRList['MR3'])> 0 ) ) {
foreach ($RvMRList['MR3'] as $mr)  {?>
<tr class="sf_admin_row_<?echo ($key++)%2?>">
      <td >
      <? echo $mr->getMrno();
      ?>
      </td>
      <td >
      <a href=<?echo url_for('po/resolveRVMR?mr3_id='. $mr->getId())?>>Resolve</a>
      </td>
</tr>
<?} }?>

</table>

<?}?>

<? if (isset($MRListCreatePO) && count($MRListCreatePO)) {?>
<h4>CREATE PO</h4>

<table id ='tast' cellspacing="1" class="sf_admin_list" width="100%">
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" >MR</th>
      <th id="sf_admin_list_th_productcode" width="5%">Action</th>
      <th id="sf_admin_list_th_productcode" width="25%">MR Sub</th>
      <th id="sf_admin_list_th_productcode" width="5%">Action</th>
      <th id="sf_admin_list_th_productcode" width="25%">MR Raw</th>
      <th id="sf_admin_list_th_productcode" width="5%">Action</th>
</tr>
</thead>
<!----->
<? 
  $countmr = 0;
  $countmr2 = 0;
  $countmr3 = 0;
  
 if (!isset($MRListCreatePO['MR']))
 {
    $countmr =0;
 }
 else
 {
     $countmr = count($MRListCreatePO['MR']);
 }
 if (!isset($MRListCreatePO['MR2']))
 {
   $countmr2 =0;
 }
 else
 {
     $countmr2 = count($MRListCreatePO['MR2']);
 }
 if (!isset($MRListCreatePO['MR3']))
 {
    $countmr3 = 0;
 }
 else
 {
     $countmr3 = count($MRListCreatePO['MR3']);
 }

for ($i = 0; $i < max($countmr,$countmr2,$countmr3); $i++)
{
    $obj1 = null; $obj2 = null; $obj3= null;
    if ($i < count($MRListCreatePO['MR'])) $obj1 = $MRListCreatePO['MR'][$i];
    if ($i < $countmr2) $obj2 = $MRListCreatePO['MR2'][$i];
    if ($i <  $countmr3) $obj3 = $MRListCreatePO['MR3'][$i];
    ?>
    <tr class="sf_admin_row_<?echo $i % 2 ?>">
        <td>
            <? echo isset($obj1) ? $obj1->getMrno().':'.$obj1->getProject(): '';?>
        </td>

        <td>
            <?php echo isset($obj1) ? link_to(image_tag('/sf/sf_admin/images/add.png', array('alt' =>'create PO', 'title' => 'Create PO')), 'po/create?mr_id='.$obj1->getId()) : '';  ?>
        </td>
        <td>
            <? echo isset($obj2) ? $obj2->getMrno(): '';?>
        </td>

        <td>
            <?php echo isset($obj2) ? link_to(image_tag('/sf/sf_admin/images/add.png', array('alt' =>'create PO', 'title' => 'Create PO')), 'po/create?mr_id='.$obj2->getId()) : '';  ?>
        </td>
        <td>
            <? echo isset($obj3) ? $obj3->getMrno(): '';?>
        </td>

        <td>
            <?php echo isset($obj3) ? link_to(image_tag('/sf/sf_admin/images/add.png', array('alt' =>'create PO', 'title' => 'Create PO')), 'po/create?mr_id='.$obj3->getId()) : '';  ?>
        </td>
    </tr>
<?
}?>
  <!---->
</table>
<?}?>

<h4>MANAGE WAREHOUSE</h4>
<table id ='task' cellspacing="2" class="sf_admin_list" width="100%">
<tr>
<?
    for ($i=0; $i < count($function['mod']); $i++) {    
        if ($i % 4 == 0)
            echo '</tr><tr class="sf_admin_row_1">';
?>
            <td width="25%">
            <a href=<?echo url_for($function['link'][$i])?>><?echo $function['mod'][$i]?></a>
            </td>
<?         
    }
    if (count($function['mod']) % 4 != 0)
    for ($i = count($function['mod']) % 4; $i < 4; $i++) {
?>
            <td width="25%">
            </td>
<?        
    }
?>
</tr>
</table>
</td>
<td width="18%"></td>
</tr>
</table>
</div>

</div>

